<template>
	<view class="new_page">
		<view class="search_wrap">
			<uni-search-bar class="uni-mt-0" radius="100" placeholder="请输入活动名称" clearButton="auto" cancelButton="none"
				@confirm="search" @clear="getList()"/>
		</view>
		<view class="main">
			<view class="tag_wrap">
				<view class="tag_item" @click="statuscheck(index)" :class="{'active':activeIndex==index}"
					v-for="(item,index) in tagList" :key="index">
					<text>{{item}}</text>
				</view>
			</view>

			<view class="content">
				<view class="content_item" v-for="(item,index) in tagList" :key="index">
					<view class="hd_wrap" v-if="activeIndex==index">
						<template v-if="actList.length>0">
							<view class="act_item" v-for="(item,index) in actList" :key="index" @click="goToPage('/pages/actAdd/actAdd?id='+item.eventId)">
								<view :class="['tt',item.status==1?'active':'']">
									<text>{{item.status==1?'进行中':'已结束'}}</text>
								</view>
								<view class="img">
									<image :src="item.eventImageList.split(';')[0]" mode="aspectFill"></image>
								</view>
								<view class="act_info">
									<view class="no-wrap">
										<text class="no-wrap">{{item.eventName}}</text>
									</view>
									<view class="sm_tip">活动时间：<text>{{item.eventTime}}</text></view>
									<view class="sm_tip"><text>优惠活动：{{getPriceCount(item.eventPrice,item.eventDiscountPrice)}}</text></view>
									<view class="price"><text class="pp">¥{{item.eventDiscountPrice}}</text><text
											class="tag">{{item.status==1?'开启活动':'活动结束'}}</text></view>
								</view>
							</view>
						</template>
						<template v-else>
							<empty></empty>
						</template>
					</view>
				</view>
			</view>
		</view>

		<view class="fix_btn">
			<button class="b-bg" @click="goToPage('/pages/actAdd/actAdd')">新增活动</button>
		</view>
	</view>
</template>

<script>
	import { getActList } from '@/request/api.js'
	
	export default {
		data() {
			return {
				activeIndex: 0,
				tagList: [
					'全部',
					'进行中',
					// '已暂停',
					'已结束',
				],
				status:0,
				actList: []
			}
		},
		onLoad() {
		},
		onShow: function() {
			console.log('center show')
			// this.userLogin();
		},
		created(){			
		},
		onShow(){
			this.getList()
		},
		mounted(){
		},
		methods: {
			// 计算折扣优惠
			getPriceCount(price,zkPrice){
				let zk = zkPrice / price * 10;
				if(Math.round(zk)>=10){
					return "无优惠"
				}else{
					return zk.toFixed(1) + "折";
				}
			},
			//状态切换
			async statuscheck(e){
				this.activeIndex = e
				let name = this.name
				let status = e
				let res =  await getActList({name:name,status:status});
				this.actList = res.data;
			},
			async search(e) {
				let name = e.value
				this.name = name
				let status = this.activeIndex
				let res =  await getActList({name:name,status:status});
				this.actList = res.data;
			},
			async getList(){
				this.name = "";
				let name = this.name
				let status = this.activeIndex
				let res =  await getActList({name:name,status:status});
				this.actList = res.data;
			}
		}
	}
</script>

<style lang="scss" scoped>
	.new_page {
		padding-bottom: 120rpx;
	}
	.search_wrap {
		background-color: #2C65BB;
	}

	.fix_btn {
		position: fixed;
		width: 90%;
		left: 0;
		right: 0;
		margin: auto;
		bottom: 40rpx;
		border-radius: 60rpx;
		overflow: hidden;
	}

	.tag_wrap {
		margin: auto;
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 0 80rpx;
		position: sticky;
		top: 0;
		z-index: 1;
		background-color: #F2F2F2;

		.tag_item {
			position: relative;
			font-size: 28rpx;
			color: $text-grey;
			padding: 6rpx 20rpx;
			margin: 30rpx 0;

			&.active {
				color: $uni-primary;

				&::after {
					content: "";
					position: absolute;
					left: 0;
					right: 0;
					bottom: -4rpx;
					margin: auto;
					width: 70%;
					height: 2px;
					background-color: $uni-primary;
				}
			}
		}
	}

	.hd_wrap {
		.act_item {
			position: relative;
			padding: 30rpx;
			display: flex;
			justify-content: flex-start;
			align-items: center;
			background-color: #fff;
			border-radius: 20rpx;
			&:nth-child(n+2) {
				margin-top: 30rpx;
			}
			.act_info {
				flex: 1;
			}
			.tt {
				position: absolute;
				left: 0;
				top: -6rpx;
				padding: 0rpx 8rpx;
				border-radius: 50rpx;
				border-top-left-radius: 0rpx;
				background-color: #ffc32b;
				color: $text-grey;
				font-size: 24rpx;
				&.active {
					background-color: $uni-primary;
					color: #fff;
				}
			}

			.img image {
				width: 160rpx;
				height: 160rpx;
				margin-right: 30rpx;
			}
			
			.sm_tip {
				color: $text-grey;
				font-size: 24rpx;
				padding-bottom: 10rpx;
			}

			.price {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding-top: 10rpx;
				border-top: 1rpx solid #f5f5f5;

				.pp {
					font-size: 34rpx;
				}

				.tag {
					background-color: #e2eafe;
					padding: 0 8rpx;
					color: $uni-primary;
					font-size: 24rpx;
				}
			}
		}
	}

	.content {
		padding: 30rpx;
	}
</style>
